package com.cac.demo.controller.logMonitor;


import com.cac.demo.controller.CallInterFace.SendMaterialInterface;
import com.cac.demo.service.logMonitor.MESLogResendService;
import com.cac.demo.util.adapter.ResponseMsg;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @className: MESLogResendService
 * @description: （描述这个类的作用）
 * @author:
 * @date: 2023/7/20 14:48:48 周四
 * @version: 1.0
 */
@RestController
@Slf4j
@RequestMapping("/MESLogResend")
public class MESLogResendRest {
    @Autowired
    private MESLogResendService mesLogResendService;
    @Autowired
    private SendMaterialInterface sendMaterialInterface;

    @PostMapping("/searchDispatchedData")
    public PageInfo searchDispatchedData(@RequestBody HashMap param) {
        HashMap queryParam = (HashMap) param.get("queryParam");
        HashMap page = (HashMap) param.get("page");
        int startPage = Integer.parseInt(page.get("currentPage").toString());
        int pageSize = Integer.parseInt(page.get("pageSize").toString());
        return mesLogResendService.searchDispatchedData(startPage, pageSize, queryParam);
    }

    @PostMapping("/reSendToMES")
    public ResponseMsg reSendToMES(@RequestBody HashMap map) {
        ResponseMsg responseMsg = new ResponseMsg();
        //网闸数据打包接口所需参数，以及发送文件所需func
        HashMap paramMap = new HashMap();
        //网闸查询场景编码
        paramMap.put("dmsCode", "ms_gzbps");
        //网闸查询数据SQL所需条件
        paramMap.put("delivery_plan_code", map.get("groupCode").toString());
        log.info("重推配送数据"+":gourpCode::"+map.get("groupCode").toString());
        HashMap interfaceMap = new HashMap();
        interfaceMap.put("code", "getMatchData");
        interfaceMap.put("name", "获取数据配套场景的配套数据");
        interfaceMap.put("parameters", paramMap);
        //发送文件所需func
        interfaceMap.put("func", "101-MES-FenjianMaterialSend");
        interfaceMap.put("sendScenario", "物料配送");
        //文件上传ERP
        HashMap rsl = sendMaterialInterface.SendFileInterface(interfaceMap);

        if (rsl.get("retCode").equals("200")) {
            responseMsg.setRetCode("200").setMessage("配送数据保存成功！");
        } else {
            responseMsg.setRetCode("201").setMessage("物料数据上传MES失败！");
        }
        return responseMsg;
    }
}
